package com.ruoyi.pingjiao.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.pingjiao.domain.Evaluation;
import com.ruoyi.pingjiao.domain.vo.TeacherWithPaperVo;
import com.ruoyi.pingjiao.mapper.TeacherWithPaperVoMapper;
import com.ruoyi.pingjiao.service.IEvaluationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.pingjiao.mapper.EvaluationPaperMapper;
import com.ruoyi.pingjiao.domain.EvaluationPaper;
import com.ruoyi.pingjiao.service.IEvaluationPaperService;

/**
 * 评教问卷管理Service业务层处理
 *
 * @author ruoyi
 * @date 2022-10-22
 */
@Service
public class EvaluationPaperServiceImpl implements IEvaluationPaperService
{
    @Autowired
    private EvaluationPaperMapper evaluationPaperMapper;
    @Autowired
    private IEvaluationService evaluationService;
    @Autowired
    private TeacherWithPaperVoMapper teacherWithPaperVoMapper;

    /**
     * 查询评教问卷管理
     *
     * @param evaluationPaperId 评教问卷管理主键
     * @return 评教问卷管理
     */
    @Override
    public EvaluationPaper selectEvaluationPaperByEvaluationPaperId(Long evaluationPaperId)
    {
        EvaluationPaper paper = evaluationPaperMapper.selectEvaluationPaperByEvaluationPaperId(evaluationPaperId);
        return paper;
    }

    @Override
    public EvaluationPaper selectEvaluationPaperByEvaluationPaperType(String evaluationPaperType) {
        return evaluationPaperMapper.selectEvaluationPaperByEvaluationPaperType(evaluationPaperType);
    }


//    @Override
//    public TeacherWithPaperVo selectTeacherWithPaperVoByEvaluationPaperType(long teacherId, String teacherName,String courseType, long courseclassId, long evaluationActivityId) {
//
//       TeacherWithPaperVo teacherWithPaperVo =
//                teacherWithPaperVoMapper.selectEvaluationPaperByEvaluationPaperType(courseType);
//        teacherWithPaperVo.setTeacherId(teacherId);
//        teacherWithPaperVo.setTeacherName(teacherName);
//        teacherWithPaperVo.setCourseclassId(courseclassId);
//        teacherWithPaperVo.setEvalutionActivityId(evaluationActivityId);
//
//        return teacherWithPaperVo;
//    }
    @Override
    public TeacherWithPaperVo selectTeacherWithPaperVoByEvaluationId( Long evaluationId) {

        TeacherWithPaperVo teacherWithPaperVo =
                teacherWithPaperVoMapper.selectEvaluationPaperByEvaluationId(evaluationId);
        return teacherWithPaperVo;
    }
    @Override
    public TeacherWithPaperVo selectTeacherWithResultVoByEvaluationId( Long evaluationId) {

        TeacherWithPaperVo teacherWithPaperVo =
                teacherWithPaperVoMapper.selectEvaluationResultByEvaluationId(evaluationId);
        return teacherWithPaperVo;
    }

    /**
     * 查询评教问卷管理列表
     *
     * @param evaluationPaper 评教问卷管理
     * @return 评教问卷管理
     */
    @Override
    public List<EvaluationPaper> selectEvaluationPaperList(EvaluationPaper evaluationPaper)
    {
        return evaluationPaperMapper.selectEvaluationPaperList(evaluationPaper);
    }

    /**
     * 新增评教问卷管理
     *
     * @param evaluationPaper 评教问卷管理
     * @return 结果
     */
    @Override
    public int insertEvaluationPaper(EvaluationPaper evaluationPaper)
    {
        evaluationPaper.setCreateTime(DateUtils.getNowDate());
        return evaluationPaperMapper.insertEvaluationPaper(evaluationPaper);
    }

    /**
     * 修改评教问卷管理
     *
     * @param evaluationPaper 评教问卷管理
     * @return 结果
     */
    @Override
    public int updateEvaluationPaper(EvaluationPaper evaluationPaper)
    {
        evaluationPaper.setUpdateTime(DateUtils.getNowDate());
        return evaluationPaperMapper.updateEvaluationPaper(evaluationPaper);
    }

    /**
     * 批量删除评教问卷管理
     *
     * @param evaluationPaperIds 需要删除的评教问卷管理主键
     * @return 结果
     */
    @Override
    public int deleteEvaluationPaperByEvaluationPaperIds(Long[] evaluationPaperIds)
    {
        return evaluationPaperMapper.deleteEvaluationPaperByEvaluationPaperIds(evaluationPaperIds);
    }

    /**
     * 删除评教问卷管理信息
     *
     * @param evaluationPaperId 评教问卷管理主键
     * @return 结果
     */
    @Override
    public int deleteEvaluationPaperByEvaluationPaperId(Long evaluationPaperId)
    {
        return evaluationPaperMapper.deleteEvaluationPaperByEvaluationPaperId(evaluationPaperId);
    }

    /**
     * @author hpf
     * @param evaluationId
     * @return
     */
    @Override
    public TeacherWithPaperVo selectEvaluationPaperOrResultByEvaluationId(Long evaluationId){
    //        判断是否已经评价
        Evaluation evaluation = evaluationService.selectEvaluationByEvaluationId(evaluationId);
        TeacherWithPaperVo vo =new TeacherWithPaperVo();
        float score = Float.valueOf(evaluation.getSumScore());
        if(score==0){
            vo = selectTeacherWithPaperVoByEvaluationId(evaluationId);
        }else {
            vo = selectTeacherWithResultVoByEvaluationId(evaluationId);
        }
        vo.setScore(score);
        return vo;

    }

}
